home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gas_251.zip / bin_251 / bfd / coffswap.h < prev    next >
C/C++ Source or Header  |  1994-10-13  |  26KB  |  745 lines

  1. /* Generic COFF swapping routines, for BFD.
  2.    Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* This file contains routines used to swap COFF data.  It is a header
  22.    file because the details of swapping depend on the details of the
  23.    structures used by each COFF implementation.  This is included by
  24.    coffcode.h, as well as by the ECOFF backend.
  25.  
  26.    Any file which uses this must first include "coff/internal.h" and
  27.    "coff/CPU.h".  The functions will then be correct for that CPU.  */
  28.  
  29. #define PUTWORD bfd_h_put_32
  30. #define PUTHALF bfd_h_put_16
  31. #define    PUTBYTE bfd_h_put_8
  32.  
  33. #ifndef GET_FCN_LNNOPTR
  34. #define GET_FCN_LNNOPTR(abfd, ext)  bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
  35. #endif
  36.  
  37. #ifndef GET_FCN_ENDNDX
  38. #define GET_FCN_ENDNDX(abfd, ext)  bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
  39. #endif
  40.  
  41. #ifndef PUT_FCN_LNNOPTR
  42. #define PUT_FCN_LNNOPTR(abfd, in, ext)  PUTWORD(abfd,  in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
  43. #endif
  44. #ifndef PUT_FCN_ENDNDX
  45. #define PUT_FCN_ENDNDX(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
  46. #endif
  47. #ifndef GET_LNSZ_LNNO
  48. #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
  49. #endif
  50. #ifndef GET_LNSZ_SIZE
  51. #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
  52. #endif
  53. #ifndef PUT_LNSZ_LNNO
  54. #define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
  55. #endif
  56. #ifndef PUT_LNSZ_SIZE
  57. #define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
  58. #endif
  59. #ifndef GET_SCN_SCNLEN
  60. #define GET_SCN_SCNLEN(abfd,  ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
  61. #endif
  62. #ifndef GET_SCN_NRELOC
  63. #define GET_SCN_NRELOC(abfd,  ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
  64. #endif
  65. #ifndef GET_SCN_NLINNO
  66. #define GET_SCN_NLINNO(abfd, ext)  bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
  67. #endif
  68. #ifndef PUT_SCN_SCNLEN
  69. #define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
  70. #endif
  71. #ifndef PUT_SCN_NRELOC
  72. #define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
  73. #endif
  74. #ifndef PUT_SCN_NLINNO
  75. #define PUT_SCN_NLINNO(abfd,in, ext)  bfd_h_put_16(abfd,in, (bfd_byte  *) ext->x_scn.x_nlinno)
  76. #endif
  77. #ifndef GET_LINENO_LNNO
  78. #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
  79. #endif
  80. #ifndef PUT_LINENO_LNNO
  81. #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val,  (bfd_byte *) (ext->l_lnno));
  82. #endif
  83.  
  84. /* The f_symptr field in the filehdr is sometimes 64 bits.  */
  85. #ifndef GET_FILEHDR_SYMPTR
  86. #define GET_FILEHDR_SYMPTR bfd_h_get_32
  87. #endif
  88. #ifndef PUT_FILEHDR_SYMPTR
  89. #define PUT_FILEHDR_SYMPTR bfd_h_put_32
  90. #endif
  91.  
  92. /* Some fields in the aouthdr are sometimes 64 bits.  */
  93. #ifndef GET_AOUTHDR_TSIZE
  94. #define GET_AOUTHDR_TSIZE bfd_h_get_32
  95. #endif
  96. #ifndef PUT_AOUTHDR_TSIZE
  97. #define PUT_AOUTHDR_TSIZE bfd_h_put_32
  98. #endif
  99. #ifndef GET_AOUTHDR_DSIZE
  100. #define GET_AOUTHDR_DSIZE bfd_h_get_32
  101. #endif
  102. #ifndef PUT_AOUTHDR_DSIZE
  103. #define PUT_AOUTHDR_DSIZE bfd_h_put_32
  104. #endif
  105. #ifndef GET_AOUTHDR_BSIZE
  106. #define GET_AOUTHDR_BSIZE bfd_h_get_32
  107. #endif
  108. #ifndef PUT_AOUTHDR_BSIZE
  109. #define PUT_AOUTHDR_BSIZE bfd_h_put_32
  110. #endif
  111. #ifndef GET_AOUTHDR_ENTRY
  112. #define GET_AOUTHDR_ENTRY bfd_h_get_32
  113. #endif
  114. #ifndef PUT_AOUTHDR_ENTRY
  115. #define PUT_AOUTHDR_ENTRY bfd_h_put_32
  116. #endif
  117. #ifndef GET_AOUTHDR_TEXT_START
  118. #define GET_AOUTHDR_TEXT_START bfd_h_get_32
  119. #endif
  120. #ifndef PUT_AOUTHDR_TEXT_START
  121. #define PUT_AOUTHDR_TEXT_START bfd_h_put_32
  122. #endif
  123. #ifndef GET_AOUTHDR_DATA_START
  124. #define GET_AOUTHDR_DATA_START bfd_h_get_32
  125. #endif
  126. #ifndef PUT_AOUTHDR_DATA_START
  127. #define PUT_AOUTHDR_DATA_START bfd_h_put_32
  128. #endif
  129.  
  130. /* Some fields in the scnhdr are sometimes 64 bits.  */
  131. #ifndef GET_SCNHDR_PADDR
  132. #define GET_SCNHDR_PADDR bfd_h_get_32
  133. #endif
  134. #ifndef PUT_SCNHDR_PADDR
  135. #define PUT_SCNHDR_PADDR bfd_h_put_32
  136. #endif
  137. #ifndef GET_SCNHDR_VADDR
  138. #define GET_SCNHDR_VADDR bfd_h_get_32
  139. #endif
  140. #ifndef PUT_SCNHDR_VADDR
  141. #define PUT_SCNHDR_VADDR bfd_h_put_32
  142. #endif
  143. #ifndef GET_SCNHDR_SIZE
  144. #define GET_SCNHDR_SIZE bfd_h_get_32
  145. #endif
  146. #ifndef PUT_SCNHDR_SIZE
  147. #define PUT_SCNHDR_SIZE bfd_h_put_32
  148. #endif
  149. #ifndef GET_SCNHDR_SCNPTR
  150. #define GET_SCNHDR_SCNPTR bfd_h_get_32
  151. #endif
  152. #ifndef PUT_SCNHDR_SCNPTR
  153. #define PUT_SCNHDR_SCNPTR bfd_h_put_32
  154. #endif
  155. #ifndef GET_SCNHDR_RELPTR
  156. #define GET_SCNHDR_RELPTR bfd_h_get_32
  157. #endif
  158. #ifndef PUT_SCNHDR_RELPTR
  159. #define PUT_SCNHDR_RELPTR bfd_h_put_32
  160. #endif
  161. #ifndef GET_SCNHDR_LNNOPTR
  162. #define GET_SCNHDR_LNNOPTR bfd_h_get_32
  163. #endif
  164. #ifndef PUT_SCNHDR_LNNOPTR
  165. #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
  166. #endif
  167.  
  168. #ifndef NO_COFF_RELOCS
  169.  
  170. static void
  171. coff_swap_reloc_in (abfd, src, dst)
  172.      bfd *abfd;
  173.      PTR src;
  174.      PTR dst;
  175. {
  176.   RELOC *reloc_src = (RELOC *) src;
  177.   struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
  178.  
  179.   reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
  180.   reloc_dst->r_symndx = bfd_h_get_signed_32(abfd, (bfd_byte *) reloc_src->r_symndx);
  181.  
  182. #ifdef RS6000COFF_C
  183.   reloc_dst->r_type = bfd_h_get_8(abfd, reloc_src->r_type);
  184.   reloc_dst->r_size = bfd_h_get_8(abfd, reloc_src->r_size);
  185. #else
  186.   reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
  187. #endif
  188.  
  189. #ifdef SWAP_IN_RELOC_OFFSET
  190.   reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
  191.                          (bfd_byte *) reloc_src->r_offset);
  192. #endif
  193. }
  194.  
  195.  
  196. static unsigned int
  197. coff_swap_reloc_out (abfd, src, dst)
  198.      bfd       *abfd;
  199.      PTR    src;
  200.      PTR    dst;
  201. {
  202.   struct internal_reloc *reloc_src = (struct internal_reloc *)src;
  203.   struct external_reloc *reloc_dst = (struct external_reloc *)dst;
  204.   bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
  205.   bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
  206.  
  207. #ifdef RS6000COFF_C
  208.   bfd_h_put_8 (abfd, reloc_src->r_type, (bfd_byte *) reloc_dst->r_type);
  209.   bfd_h_put_8 (abfd, reloc_src->r_size, (bfd_byte *) reloc_dst->r_size);
  210. #else
  211.   bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
  212.            reloc_dst->r_type);
  213. #endif
  214.  
  215. #ifdef SWAP_OUT_RELOC_OFFSET
  216.   SWAP_OUT_RELOC_OFFSET(abfd,
  217.             reloc_src->r_offset,
  218.             (bfd_byte *) reloc_dst->r_offset);
  219. #endif
  220. #ifdef SWAP_OUT_RELOC_EXTRA
  221.   SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
  222. #endif
  223.  
  224.   return sizeof(struct external_reloc);
  225. }
  226.  
  227. #endif /* NO_COFF_RELOCS */
  228.  
  229. static void
  230. coff_swap_filehdr_in (abfd, src, dst)
  231.      bfd            *abfd;
  232.      PTR         src;
  233.      PTR         dst;
  234. {
  235.   FILHDR *filehdr_src = (FILHDR *) src;
  236.   struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
  237.   filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
  238.   filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
  239.   filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
  240.   filehdr_dst->f_symptr =
  241.     GET_FILEHDR_SYMPTR (abfd, (bfd_byte *) filehdr_src->f_symptr);
  242.   filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
  243.   filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr);
  244.   filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
  245. }
  246.  
  247. static  unsigned int
  248. coff_swap_filehdr_out (abfd, in, out)
  249.      bfd       *abfd;
  250.      PTR    in;
  251.      PTR    out;
  252. {
  253.   struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
  254.   FILHDR *filehdr_out = (FILHDR *)out;
  255.   bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
  256.   bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
  257.   bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
  258.   PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
  259.               (bfd_byte *) filehdr_out->f_symptr);
  260.   bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
  261.   bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
  262.   bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
  263.   return sizeof(FILHDR);
  264. }
  265.  
  266.  
  267. #ifndef NO_COFF_SYMBOLS
  268.  
  269. static void
  270. coff_swap_sym_in (abfd, ext1, in1)
  271.      bfd            *abfd;
  272.      PTR ext1;
  273.      PTR in1;
  274. {
  275.   SYMENT *ext = (SYMENT *)ext1;
  276.   struct internal_syment      *in = (struct internal_syment *)in1;
  277.  
  278.   if( ext->e.e_name[0] == 0) {
  279.     in->_n._n_n._n_zeroes = 0;
  280.     in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
  281.   }
  282.   else {
  283. #if SYMNMLEN != E_SYMNMLEN
  284.    -> Error, we need to cope with truncating or extending SYMNMLEN!;
  285. #else
  286.     memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
  287. #endif
  288.   }
  289.   in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
  290.   in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
  291.   if (sizeof(ext->e_type) == 2){
  292.     in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
  293.   }
  294.   else {
  295.     in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type);
  296.   }
  297.   in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
  298.   in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
  299. }
  300.  
  301. static unsigned int
  302. coff_swap_sym_out (abfd, inp, extp)
  303.      bfd       *abfd;
  304.      PTR    inp;
  305.      PTR    extp;
  306. {
  307.   struct internal_syment *in = (struct internal_syment *)inp;
  308.   SYMENT *ext =(SYMENT *)extp;
  309.   if(in->_n._n_name[0] == 0) {
  310.     bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
  311.     bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *)  ext->e.e.e_offset);
  312.   }
  313.   else {
  314. #if SYMNMLEN != E_SYMNMLEN
  315.     -> Error, we need to cope with truncating or extending SYMNMLEN!;
  316. #else
  317.     memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
  318. #endif
  319.   }
  320.   bfd_h_put_32(abfd,  in->n_value , (bfd_byte *) ext->e_value);
  321.   bfd_h_put_16(abfd,  in->n_scnum , (bfd_byte *) ext->e_scnum);
  322.   if (sizeof(ext->e_type) == 2)
  323.       {
  324.     bfd_h_put_16(abfd,  in->n_type , (bfd_byte *) ext->e_type);
  325.       }
  326.   else
  327.       {
  328.     bfd_h_put_32(abfd,  in->n_type , (bfd_byte *) ext->e_type);
  329.       }
  330.   bfd_h_put_8(abfd,  in->n_sclass , ext->e_sclass);
  331.   bfd_h_put_8(abfd,  in->n_numaux , ext->e_numaux);
  332.   return sizeof(SYMENT);
  333. }
  334.  
  335. static void
  336. coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
  337.      bfd            *abfd;
  338.      PTR           ext1;
  339.      int             type;
  340.      int             class;
  341.      int          indx;
  342.      int          numaux;
  343.      PTR           in1;
  344. {
  345.   AUXENT    *ext = (AUXENT *)ext1;
  346.   union internal_auxent *in = (union internal_auxent *)in1;
  347.  
  348.   switch (class) {
  349.     case C_FILE:
  350.       if (ext->x_file.x_fname[0] == 0) {
  351.       in->x_file.x_n.x_zeroes = 0;
  352.       in->x_file.x_n.x_offset = 
  353.        bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
  354.     } else {
  355. #if FILNMLEN != E_FILNMLEN
  356.         -> Error, we need to cope with truncating or extending FILNMLEN!;
  357. #else
  358.         memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
  359. #endif
  360.       }
  361.       return;
  362.  
  363.       /* RS/6000 "csect" auxents */
  364. #ifdef RS6000COFF_C
  365.     case C_EXT:
  366.     case C_HIDEXT:
  367.       if (indx + 1 == numaux)
  368.     {
  369.       in->x_csect.x_scnlen.l = bfd_h_get_32 (abfd, ext->x_csect.x_scnlen);
  370.       in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
  371.                          ext->x_csect.x_parmhash);
  372.       in->x_csect.x_snhash   = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
  373.       /* We don't have to hack bitfields in x_smtyp because it's
  374.          defined by shifts-and-ands, which are equivalent on all
  375.          byte orders.  */
  376.       in->x_csect.x_smtyp    = bfd_h_get_8  (abfd, ext->x_csect.x_smtyp);
  377.       in->x_csect.x_smclas   = bfd_h_get_8  (abfd, ext->x_csect.x_smclas);
  378.       in->x_csect.x_stab     = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
  379.       in->x_csect.x_snstab   = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
  380.       return;
  381.     }
  382.       break;
  383. #endif
  384.  
  385.     case C_STAT:
  386. #ifdef C_LEAFSTAT
  387.     case C_LEAFSTAT:
  388. #endif
  389.     case C_HIDDEN:
  390.       if (type == T_NULL) {
  391.       in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
  392.       in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
  393.       in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
  394.       return;
  395.     }
  396.       break;
  397.     }
  398.  
  399.   in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
  400. #ifndef NO_TVNDX
  401.   in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
  402. #endif
  403.  
  404.   if (ISARY(type)) {
  405. #if DIMNUM != E_DIMNUM
  406.     -> Error, we need to cope with truncating or extending DIMNUM!;
  407. #else
  408.     in->x_sym.x_fcnary.x_ary.x_dimen[0] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
  409.     in->x_sym.x_fcnary.x_ary.x_dimen[1] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
  410.     in->x_sym.x_fcnary.x_ary.x_dimen[2] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
  411.     in->x_sym.x_fcnary.x_ary.x_dimen[3] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
  412. #endif
  413.   }
  414.   if (class == C_BLOCK || ISFCN(type) || ISTAG(class)) {
  415.     in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR(abfd, ext);
  416.     in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX(abfd, ext);
  417.   }
  418.  
  419.   if (ISFCN(type)) {
  420.     in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
  421.   }
  422.   else {
  423.     in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
  424.     in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
  425.   }
  426. }
  427.  
  428. static unsigned int
  429. coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
  430.      bfd   *abfd;
  431.      PTR     inp;
  432.      int   type;
  433.      int   class;
  434.      int   indx;
  435.      int   numaux;
  436.      PTR    extp;
  437. {
  438.   union internal_auxent *in = (union internal_auxent *)inp;
  439.   AUXENT *ext = (AUXENT *)extp;
  440.  
  441.   memset((PTR)ext, 0, AUXESZ);
  442.   switch (class) {
  443.   case C_FILE:
  444.     if (in->x_file.x_fname[0] == 0) {
  445.       PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
  446.       PUTWORD(abfd,
  447.           in->x_file.x_n.x_offset,
  448.           (bfd_byte *) ext->x_file.x_n.x_offset);
  449.     }
  450.     else {
  451. #if FILNMLEN != E_FILNMLEN
  452.       -> Error, we need to cope with truncating or extending FILNMLEN!;
  453. #else
  454.       memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
  455. #endif
  456.     }
  457.     return sizeof (AUXENT);
  458.  
  459. #ifdef RS6000COFF_C
  460.   /* RS/6000 "csect" auxents */
  461.   case C_EXT:
  462.   case C_HIDEXT:
  463.     if (indx + 1 == numaux)
  464.       {
  465.     PUTWORD (abfd, in->x_csect.x_scnlen.l,    ext->x_csect.x_scnlen);
  466.     PUTWORD (abfd, in->x_csect.x_parmhash,    ext->x_csect.x_parmhash);
  467.     PUTHALF (abfd, in->x_csect.x_snhash,    ext->x_csect.x_snhash);
  468.     /* We don't have to hack bitfields in x_smtyp because it's
  469.        defined by shifts-and-ands, which are equivalent on all
  470.        byte orders.  */
  471.     PUTBYTE (abfd, in->x_csect.x_smtyp,    ext->x_csect.x_smtyp);
  472.     PUTBYTE (abfd, in->x_csect.x_smclas,    ext->x_csect.x_smclas);
  473.     PUTWORD (abfd, in->x_csect.x_stab,    ext->x_csect.x_stab);
  474.     PUTHALF (abfd, in->x_csect.x_snstab,    ext->x_csect.x_snstab);
  475.     return sizeof (AUXENT);
  476.       }
  477.     break;
  478. #endif
  479.  
  480.   case C_STAT:
  481. #ifdef C_LEAFSTAT
  482.   case C_LEAFSTAT:
  483. #endif
  484.   case C_HIDDEN:
  485.     if (type == T_NULL) {
  486.       PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
  487.       PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
  488.       PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
  489.       return sizeof (AUXENT);
  490.     }
  491.     break;
  492.   }
  493.  
  494.   PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
  495. #ifndef NO_TVNDX
  496.   bfd_h_put_16(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
  497. #endif
  498.  
  499.   if (class == C_BLOCK || ISFCN(type) || ISTAG(class)) {
  500.     PUT_FCN_LNNOPTR(abfd,  in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
  501.     PUT_FCN_ENDNDX(abfd,  in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
  502.   }
  503.  
  504.   if (ISFCN(type)) {
  505.     PUTWORD(abfd, in->x_sym.x_misc.x_fsize, (bfd_byte *)  ext->x_sym.x_misc.x_fsize);
  506.   }
  507.   else {
  508.     if (ISARY(type)) {
  509. #if DIMNUM != E_DIMNUM
  510.       -> Error, we need to cope with truncating or extending DIMNUM!;
  511. #else
  512.       bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
  513.       bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
  514.       bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
  515.       bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
  516. #endif
  517.     }
  518.     PUT_LNSZ_LNNO(abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
  519.     PUT_LNSZ_SIZE(abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
  520.   }
  521.   return sizeof(AUXENT);
  522. }
  523.  
  524. #endif /* NO_COFF_SYMBOLS */
  525.  
  526. #ifndef NO_COFF_LINENOS
  527.  
  528. static void
  529. coff_swap_lineno_in (abfd, ext1, in1)
  530.      bfd            *abfd;
  531.      PTR ext1;
  532.      PTR in1;
  533. {
  534.   LINENO *ext = (LINENO *)ext1;
  535.   struct internal_lineno      *in = (struct internal_lineno *)in1;
  536.  
  537.   in->l_addr.l_symndx = bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
  538.   in->l_lnno = GET_LINENO_LNNO(abfd, ext);
  539. }
  540.  
  541. static unsigned int
  542. coff_swap_lineno_out (abfd, inp, outp)
  543.      bfd       *abfd;
  544.      PTR    inp;
  545.      PTR    outp;
  546. {
  547.   struct internal_lineno *in = (struct internal_lineno *)inp;
  548.   struct external_lineno *ext = (struct external_lineno *)outp;
  549.   PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
  550.       ext->l_addr.l_symndx);
  551.  
  552.   PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
  553.   return sizeof(struct external_lineno);
  554. }
  555.  
  556. #endif /* NO_COFF_LINENOS */
  557.  
  558.  
  559. static void
  560. coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1)
  561.      bfd            *abfd;
  562.      PTR aouthdr_ext1;
  563.      PTR aouthdr_int1;
  564. {
  565.   AOUTHDR        *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
  566.   struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
  567.  
  568.   aouthdr_int->magic = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->magic);
  569.   aouthdr_int->vstamp = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->vstamp);
  570.   aouthdr_int->tsize =
  571.     GET_AOUTHDR_TSIZE (abfd, (bfd_byte *) aouthdr_ext->tsize);
  572.   aouthdr_int->dsize =
  573.     GET_AOUTHDR_DSIZE (abfd, (bfd_byte *) aouthdr_ext->dsize);
  574.   aouthdr_int->bsize =
  575.     GET_AOUTHDR_BSIZE (abfd, (bfd_byte *) aouthdr_ext->bsize);
  576.   aouthdr_int->entry =
  577.     GET_AOUTHDR_ENTRY (abfd, (bfd_byte *) aouthdr_ext->entry);
  578.   aouthdr_int->text_start =
  579.     GET_AOUTHDR_TEXT_START (abfd, (bfd_byte *) aouthdr_ext->text_start);
  580.   aouthdr_int->data_start =
  581.     GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
  582.  
  583. #ifdef I960
  584.   aouthdr_int->tagentries = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->tagentries);
  585. #endif
  586.  
  587. #ifdef APOLLO_M68
  588.   bfd_h_put_32(abfd, aouthdr_int->o_inlib, (bfd_byte *) aouthdr_ext->o_inlib);
  589.   bfd_h_put_32(abfd, aouthdr_int->o_sri, (bfd_byte *) aouthdr_ext->o_sri);
  590.   bfd_h_put_32(abfd, aouthdr_int->vid[0], (bfd_byte *) aouthdr_ext->vid);
  591.   bfd_h_put_32(abfd, aouthdr_int->vid[1], (bfd_byte *) aouthdr_ext->vid + 4);
  592. #endif
  593.  
  594.  
  595. #ifdef RS6000COFF_C
  596.   aouthdr_int->o_toc = bfd_h_get_32(abfd, aouthdr_ext->o_toc);
  597.   aouthdr_int->o_snentry = bfd_h_get_16(abfd, aouthdr_ext->o_snentry);
  598.   aouthdr_int->o_sntext = bfd_h_get_16(abfd, aouthdr_ext->o_sntext);
  599.   aouthdr_int->o_sndata = bfd_h_get_16(abfd, aouthdr_ext->o_sndata);
  600.   aouthdr_int->o_sntoc = bfd_h_get_16(abfd, aouthdr_ext->o_sntoc);
  601.   aouthdr_int->o_snloader = bfd_h_get_16(abfd, aouthdr_ext->o_snloader);
  602.   aouthdr_int->o_snbss = bfd_h_get_16(abfd, aouthdr_ext->o_snbss);
  603.   aouthdr_int->o_algntext = bfd_h_get_16(abfd, aouthdr_ext->o_algntext);
  604.   aouthdr_int->o_algndata = bfd_h_get_16(abfd, aouthdr_ext->o_algndata);
  605.   aouthdr_int->o_modtype = bfd_h_get_16(abfd, aouthdr_ext->o_modtype);
  606.   aouthdr_int->o_maxstack = bfd_h_get_32(abfd, aouthdr_ext->o_maxstack);
  607. #endif
  608.  
  609. #ifdef MIPSECOFF
  610.   aouthdr_int->bss_start = bfd_h_get_32(abfd, aouthdr_ext->bss_start);
  611.   aouthdr_int->gp_value = bfd_h_get_32(abfd, aouthdr_ext->gp_value);
  612.   aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
  613.   aouthdr_int->cprmask[0] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[0]);
  614.   aouthdr_int->cprmask[1] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[1]);
  615.   aouthdr_int->cprmask[2] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[2]);
  616.   aouthdr_int->cprmask[3] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[3]);
  617. #endif
  618.  
  619. #ifdef ALPHAECOFF
  620.   aouthdr_int->bss_start = bfd_h_get_64(abfd, aouthdr_ext->bss_start);
  621.   aouthdr_int->gp_value = bfd_h_get_64(abfd, aouthdr_ext->gp_value);
  622.   aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
  623.   aouthdr_int->fprmask = bfd_h_get_32(abfd, aouthdr_ext->fprmask);
  624. #endif
  625. }
  626.  
  627. static unsigned int
  628. coff_swap_aouthdr_out (abfd, in, out)
  629.      bfd       *abfd;
  630.      PTR    in;
  631.      PTR    out;
  632. {
  633.   struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *)in;
  634.   AOUTHDR *aouthdr_out = (AOUTHDR *)out;
  635.  
  636.   bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->magic);
  637.   bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->vstamp);
  638.   PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->tsize);
  639.   PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->dsize);
  640.   PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->bsize);
  641.   PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->entry);
  642.   PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
  643.               (bfd_byte *) aouthdr_out->text_start);
  644.   PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
  645.               (bfd_byte *) aouthdr_out->data_start);
  646. #ifdef I960
  647.   bfd_h_put_32(abfd, aouthdr_in->tagentries, (bfd_byte *) aouthdr_out->tagentries);
  648. #endif
  649.  
  650. #ifdef MIPSECOFF
  651.   bfd_h_put_32(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
  652.   bfd_h_put_32(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
  653.   bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
  654.   bfd_h_put_32(abfd, aouthdr_in->cprmask[0], (bfd_byte *) aouthdr_out->cprmask[0]);
  655.   bfd_h_put_32(abfd, aouthdr_in->cprmask[1], (bfd_byte *) aouthdr_out->cprmask[1]);
  656.   bfd_h_put_32(abfd, aouthdr_in->cprmask[2], (bfd_byte *) aouthdr_out->cprmask[2]);
  657.   bfd_h_put_32(abfd, aouthdr_in->cprmask[3], (bfd_byte *) aouthdr_out->cprmask[3]);
  658. #endif
  659.  
  660. #ifdef ALPHAECOFF
  661.   /* FIXME: What does bldrev mean?  */
  662.   bfd_h_put_16(abfd, (bfd_vma) 2, (bfd_byte *) aouthdr_out->bldrev);
  663.   bfd_h_put_16(abfd, (bfd_vma) 0, (bfd_byte *) aouthdr_out->padding);
  664.   bfd_h_put_64(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
  665.   bfd_h_put_64(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
  666.   bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
  667.   bfd_h_put_32(abfd, aouthdr_in->fprmask, (bfd_byte *) aouthdr_out->fprmask);
  668. #endif
  669.  
  670.   return sizeof(AOUTHDR);
  671. }
  672.  
  673. static void
  674. coff_swap_scnhdr_in (abfd, ext, in)
  675.      bfd            *abfd;
  676.      PTR         ext;
  677.      PTR         in;
  678. {
  679.   SCNHDR *scnhdr_ext = (SCNHDR *) ext;
  680.   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
  681.  
  682.   memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
  683.   scnhdr_int->s_vaddr =
  684.     GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
  685.   scnhdr_int->s_paddr =
  686.     GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
  687.   scnhdr_int->s_size =
  688.     GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
  689.  
  690.   scnhdr_int->s_scnptr =
  691.     GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
  692.   scnhdr_int->s_relptr =
  693.     GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
  694.   scnhdr_int->s_lnnoptr =
  695.     GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
  696.   scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
  697. #if defined(M88)
  698.   scnhdr_int->s_nreloc = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
  699.   scnhdr_int->s_nlnno = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
  700. #else
  701.   scnhdr_int->s_nreloc = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
  702.   scnhdr_int->s_nlnno = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
  703. #endif
  704. #ifdef I960
  705.   scnhdr_int->s_align = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_align);
  706. #endif
  707. }
  708.  
  709. static unsigned int
  710. coff_swap_scnhdr_out (abfd, in, out)
  711.      bfd       *abfd;
  712.      PTR    in;
  713.      PTR    out;
  714. {
  715.   struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
  716.   SCNHDR *scnhdr_ext = (SCNHDR *)out;
  717.  
  718.   memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
  719.   PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr,
  720.             (bfd_byte *) scnhdr_ext->s_vaddr);
  721.   PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr,
  722.             (bfd_byte *) scnhdr_ext->s_paddr);
  723.   PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size,
  724.            (bfd_byte *) scnhdr_ext->s_size);
  725.   PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
  726.              (bfd_byte *) scnhdr_ext->s_scnptr);
  727.   PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
  728.              (bfd_byte *) scnhdr_ext->s_relptr);
  729.   PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
  730.               (bfd_byte *) scnhdr_ext->s_lnnoptr);
  731.   PUTWORD(abfd, scnhdr_int->s_flags, (bfd_byte *) scnhdr_ext->s_flags);
  732. #if defined(M88)
  733.   PUTWORD(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
  734.   PUTWORD(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
  735. #else
  736.   PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
  737.   PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
  738. #endif
  739.  
  740. #if defined(I960)
  741.   PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);
  742. #endif
  743.   return sizeof(SCNHDR);
  744. }
  745.